using ShureValidation.Rules;

namespace ShureValidation
{
    /// <summary>
    /// Checks whether a field have been specified or not.
    /// </summary>
    /// <remarks>
    /// <para>
    /// Language file items:
    /// <list type="table">
    ///     <listheader>
    ///         <term>ItemName</term>
    ///         <description>Language text</description>
    ///     </listheader>
    ///     <item>
    ///         <term>Required</term>
    ///         <description>'{0}' is required.</description>
    ///     </item>
    /// </list>
    /// </para>
    /// </remarks>
    public class RequiredAttribute : ValidateAttribute
    {
        private readonly RequiredFlags _flags;

        /// <summary>
        /// Initializes a new instance of the <see cref="RequiredAttribute"/> class.
        /// </summary>
        public RequiredAttribute()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="RequiredAttribute"/> class.
        /// </summary>
        /// <param name="flags">The flags.</param>
        public RequiredAttribute(RequiredFlags flags)
        {
            _flags = flags;
        }

        /// <summary>
        /// Create a rule based on this attribute.
        /// </summary>
        /// <returns>Created rule</returns>
        public override IRule CreateRule()
        {
            return new RequiredRule(_flags);
        }
    }
}